package com.xczz.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisCache {
    @Autowired
    public RedisTemplate redisTemplate;

    public <T>ValueOperations<String,T> setCacheObject(String key,T value){
        ValueOperations<String,T> operations=redisTemplate.opsForValue();
        operations.set(key, value);
        return operations;
    }

    public <T> ValueOperations<String,T> setCacheObject(String key, T value, Integer timeout, TimeUnit timeUnit){
        ValueOperations<String,T> operation=redisTemplate.opsForValue();
        operation.set(key,value,timeout,timeUnit);
        return operation;
    }

    public <T> T getCacheObject(String key){
        ValueOperations<String,T> operation=redisTemplate.opsForValue();
        return operation.get(key);
    }
}
